
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "menutriggeraction.h"

#include <QMainWindow>
#include <QTableWidget>
#include <QWidget>

#include <repocache.h>
#include <columnsentry.h>

QT_BEGIN_NAMESPACE
QT_END_NAMESPACE

class RepoAnalyzerManager;
namespace Ui {
    class MainWindow;
}
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    // 来源于 TableWidget 的 Columns 信息
    Columns table_widget_item_columns_at_row(const QTableWidgetItem *item = nullptr);
    QList<Columns> table_widget_item_columns_at_rows();

    QTableWidgetItem* createQTableWidgetItem(const QString display, const QString &userData = "");
    QTableWidgetItem* createProjectNameQTableWidgetItem(const QString &dir, const QString &name);
    QTableWidgetItem* createPathQTableWidgetItem(const QString &dir, const QString &path);
    QTableWidgetItem* createCheckedQTableWidgetItem(const QString &dir, const QString &path);
    QTableWidgetItem* createSolutionQTableWidgetItem(const QString &dir, const QString &name, const QString &path);
    QTableWidgetItem* createRemoteQTableWidgetItem(const QString &dir, const QString &name, const QString &path, const QVariantMap &var);
    QTableWidgetItem* createRevisionQTableWidgetItem(const QString &dir, const QString &name, const QString &path, const QVariantMap &var);

    void loaderProjects();
    void loaderManifests();

public slots:
    void load(const QString &dir);

private slots:
    void on_chooseRepoDir_clicked();

    void on_repo_dir_path_input_textChanged(const QString &dirPath);

    void on_reload_clicked();

    void on_projectTableWidget_itemSelectionChanged();

    void on_projectManifestJson_stateChanged(int arg1);

    void on_tabWidget_currentChanged(int index);

    void on_btn_copy_project_names_clicked();

    void on_action_repo_triggered();

    void on_projectTableWidget_customContextMenuRequested(const QPoint &pos);

    void on_action_vscode_open_manifests_triggered();

    void on_action_solution_incomplete_triggered();

    void on_action_solution_solve_revision_not_found_fetch_missing_revision_triggered();

    void on_action_solution_solve_revision_not_found_delete_and_resynchronize_triggered();

    void on_action_repo_repo_git_pull_triggered();

    void on_action_solution_file_lose_weight_triggered();

    void on_edit_filter_textChanged(const QString &arg1);

    void on_action_solution_slove_git_workspace_git_init_and_resynchronization_triggered();
    
    void on_action_overlayfs_dialog_triggered();

    void on_action_repo_sync_full_synchronization_triggered();

    void on_action_open_settings_dialog_triggered();

    void on_action_repo_sync_detach_full_synchronization_triggered();

private:
    /**
     * @brief 调整 QTableWidget 的显示
     */
    void table_view_vision_adjust();
    void update_select_item_status(const QString &workdir);

private:
    Ui::MainWindow *ui;

    MenuTriggerAction *action_copy_path;
    MenuTriggerAction *action_xdgopen_dir;
    MenuTriggerAction *action_vscode_open;
#ifdef Q_OS_LINUX
    MenuTriggerAction *action_linux_terminal_open;
#endif
    MenuTriggerAction *action_vscode_open_manifests;
    QAction *action_git_reset;
    QAction *action_delete_index_lock;

    RepoCache cache;

    RepoAnalyzerManager *repo_manager;

private:
    void slot_repo_manager_solution();

    // QWidget interface
protected:
    virtual void resizeEvent(QResizeEvent *event) override;
};

#endif // MAINWINDOW_H

